{"ast":null,"code":"import _slicedToArray from \"@babel/runtime/helpers/esm/slicedToArray\";\nimport { FieldContext } from '.';\nimport warning from \"rc-util/es/warning\";\nimport { HOOK_MARK } from './FieldContext';\nimport { useState, useContext, useEffect, useRef, useMemo } from 'react';\nimport { getNamePath, getValue } from './utils/valueUtil';\nexport function stringify(value) {\n  try {\n    return JSON.stringify(value);\n  } catch (err) {\n    return Math.random();\n  }\n}\nfunction useWatch() {\n  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {\n    args[_key] = arguments[_key];\n  }\n  var _args$ = args[0],\n    dependencies = _args$ === void 0 ? [] : _args$,\n    form = args[1];\n  var _useState = useState(),\n    _useState2 = _slicedToArray(_useState, 2),\n    value = _useState2[0],\n    setValue = _useState2[1];\n  var valueStr = useMemo(function () {\n    return stringify(value);\n  }, [value]);\n  var valueStrRef = useRef(valueStr);\n  valueStrRef.current = valueStr;\n  var fieldContext = useContext(FieldContext);\n  var formInstance = form || fieldContext;\n  var isValidForm = formInstance && formInstance._init;\n  // Warning if not exist form instance\n  if (process.env.NODE_ENV !== 'production') {\n    warning(args.length === 2 ? form ? isValidForm : true : isValidForm, 'useWatch requires a form instance since it can not auto detect from context.');\n  }\n  var namePath = getNamePath(dependencies);\n  var namePathRef = useRef(namePath);\n  namePathRef.current = namePath;\n  useEffect(function () {\n    // Skip if not exist form instance\n    if (!isValidForm) {\n      return;\n    }\n    var getFieldsValue = formInstance.getFieldsValue,\n      getInternalHooks = formInstance.getInternalHooks;\n    var _getInternalHooks = getInternalHooks(HOOK_MARK),\n      registerWatch = _getInternalHooks.registerWatch;\n    var cancelRegister = registerWatch(function (store) {\n      var newValue = getValue(store, namePathRef.current);\n      var nextValueStr = stringify(newValue);\n      // Compare stringify in case it's nest object\n      if (valueStrRef.current !== nextValueStr) {\n        valueStrRef.current = nextValueStr;\n        setValue(newValue);\n      }\n    });\n    // TODO: We can improve this perf in future\n    var initialValue = getValue(getFieldsValue(), namePathRef.current);\n    setValue(initialValue);\n    return cancelRegister;\n  },\n  // We do not need re-register since namePath content is the same\n  // eslint-disable-next-line react-hooks/exhaustive-deps\n  [isValidForm]);\n  return value;\n}\nexport default useWatch;","map":{"version":3,"names":["_slicedToArray","FieldContext","warning","HOOK_MARK","useState","useContext","useEffect","useRef","useMemo","getNamePath","getValue","stringify","value","JSON","err","Math","random","useWatch","_len","arguments","length","args","Array","_key","_args$","dependencies","form","_useState","_useState2","setValue","valueStr","valueStrRef","current","fieldContext","formInstance","isValidForm","_init","process","env","NODE_ENV","namePath","namePathRef","getFieldsValue","getInternalHooks","_getInternalHooks","registerWatch","cancelRegister","store","newValue","nextValueStr","initialValue"],"sources":["/data/messenger.client/node_modules/rc-field-form/es/useWatch.js"],"sourcesContent":["import _slicedToArray from \"@babel/runtime/helpers/esm/slicedToArray\";\nimport { FieldContext } from '.';\nimport warning from \"rc-util/es/warning\";\nimport { HOOK_MARK } from './FieldContext';\nimport { useState, useContext, useEffect, useRef, useMemo } from 'react';\nimport { getNamePath, getValue } from './utils/valueUtil';\nexport function stringify(value) {\n  try {\n    return JSON.stringify(value);\n  } catch (err) {\n    return Math.random();\n  }\n}\nfunction useWatch() {\n  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {\n    args[_key] = arguments[_key];\n  }\n  var _args$ = args[0],\n    dependencies = _args$ === void 0 ? [] : _args$,\n    form = args[1];\n  var _useState = useState(),\n    _useState2 = _slicedToArray(_useState, 2),\n    value = _useState2[0],\n    setValue = _useState2[1];\n  var valueStr = useMemo(function () {\n    return stringify(value);\n  }, [value]);\n  var valueStrRef = useRef(valueStr);\n  valueStrRef.current = valueStr;\n  var fieldContext = useContext(FieldContext);\n  var formInstance = form || fieldContext;\n  var isValidForm = formInstance && formInstance._init;\n  // Warning if not exist form instance\n  if (process.env.NODE_ENV !== 'production') {\n    warning(args.length === 2 ? form ? isValidForm : true : isValidForm, 'useWatch requires a form instance since it can not auto detect from context.');\n  }\n  var namePath = getNamePath(dependencies);\n  var namePathRef = useRef(namePath);\n  namePathRef.current = namePath;\n  useEffect(function () {\n    // Skip if not exist form instance\n    if (!isValidForm) {\n      return;\n    }\n    var getFieldsValue = formInstance.getFieldsValue,\n      getInternalHooks = formInstance.getInternalHooks;\n    var _getInternalHooks = getInternalHooks(HOOK_MARK),\n      registerWatch = _getInternalHooks.registerWatch;\n    var cancelRegister = registerWatch(function (store) {\n      var newValue = getValue(store, namePathRef.current);\n      var nextValueStr = stringify(newValue);\n      // Compare stringify in case it's nest object\n      if (valueStrRef.current !== nextValueStr) {\n        valueStrRef.current = nextValueStr;\n        setValue(newValue);\n      }\n    });\n    // TODO: We can improve this perf in future\n    var initialValue = getValue(getFieldsValue(), namePathRef.current);\n    setValue(initialValue);\n    return cancelRegister;\n  },\n  // We do not need re-register since namePath content is the same\n  // eslint-disable-next-line react-hooks/exhaustive-deps\n  [isValidForm]);\n  return value;\n}\nexport default useWatch;"],"mappings":"AAAA,OAAOA,cAAc,MAAM,0CAA0C;AACrE,SAASC,YAAY,QAAQ,GAAG;AAChC,OAAOC,OAAO,MAAM,oBAAoB;AACxC,SAASC,SAAS,QAAQ,gBAAgB;AAC1C,SAASC,QAAQ,EAAEC,UAAU,EAAEC,SAAS,EAAEC,MAAM,EAAEC,OAAO,QAAQ,OAAO;AACxE,SAASC,WAAW,EAAEC,QAAQ,QAAQ,mBAAmB;AACzD,OAAO,SAASC,SAAS,CAACC,KAAK,EAAE;EAC/B,IAAI;IACF,OAAOC,IAAI,CAACF,SAAS,CAACC,KAAK,CAAC;EAC9B,CAAC,CAAC,OAAOE,GAAG,EAAE;IACZ,OAAOC,IAAI,CAACC,MAAM,EAAE;EACtB;AACF;AACA,SAASC,QAAQ,GAAG;EAClB,KAAK,IAAIC,IAAI,GAAGC,SAAS,CAACC,MAAM,EAAEC,IAAI,GAAG,IAAIC,KAAK,CAACJ,IAAI,CAAC,EAAEK,IAAI,GAAG,CAAC,EAAEA,IAAI,GAAGL,IAAI,EAAEK,IAAI,EAA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